home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Unix / ftpumich.txt < prev    next >
Encoding:
Text File  |  1993-12-27  |  7.7 KB  |  254 lines  |  [????/????]

  1. #!/bin/csh -f
  2. #
  3. #Sorry Mike (or other maintainer)
  4. #
  5. #but this is the first time I have added something.
  6. #
  7. #This is a super awesome unix ftp script (IMHO).
  8. #
  9. #I know you guys like people to use gopher and other
  10. #things but I found this to be really slick.
  11. #
  12. #I hope I put this in the right place and have given
  13. #you enough info.
  14. #
  15. #Thanks!
  16. #
  17. #-Jack
  18. #
  19. #
  20. #/---------------------------------------------------------\
  21. #|  Jack W. Judy                  Office: (510) 642-1010   |
  22. #|  Electrical Engineering        FAX:    (510) 643-6637   |
  23. #|  497 Cory Hall (BSAC)          Lab:    (510) 642-2716   |
  24. #|  University of California      Home:   (510) 849-2604   |
  25. #|  Berkeley, CA  94720           email:  j.judy@ieee.org  |
  26. #\---------------------------------------------------------/
  27. # ftpumich
  28. #
  29. # This script was written for all those people frustrated with the limited
  30. # number of guest logins at the popular umich Mac archive.  It skips from
  31. # mirror to mirror until it succeeds. It always works for me. NO MORE WAITING.
  32. #
  33. # Comments and suggestions/improvements are welcome.
  34. #
  35. # Written by Jack Judy <j.judy@ieee.org> 12-21-93
  36. #
  37.  
  38. # Some variables you may want to tweek to your liking.
  39. @ sleep_time = 0
  40. @ maxcount = 1
  41. @ VERBOSE = 1
  42.  
  43. if ( $#argv == 0 || $#argv > 1 ) then
  44.     if ( $VERBOSE == 1 ) then
  45.             echo ""
  46.             echo "usage:    ftpumich [file_containing_compete_pathnames]"
  47.             echo "usage:    ftpumich"
  48.             echo ""
  49.             echo "The file (file_containing_compete_pathnames) holds the COMPLETE"
  50.         echo "pathnames of the files you want to 'ftp'.  The pathname format"
  51.         echo "of the files is that of the awesome archive at archive.umich.edu."
  52.         echo ""
  53.         echo "Example:"
  54.         echo ""
  55.         echo "j.judy@ieee.org 22> cat new_umich_stuff"
  56.         echo "/mac/00help/newthings.txt"
  57.         echo "/mac/00ls-lRfile"
  58.         echo "j.judy@ieee.org 23> ftpumich new_umich_stuff"
  59.         echo ""
  60.         echo "The order in which the ftp sites/mirrors are attempted"
  61.         echo "is given below.  The first ftp site is choosen to be the"
  62.         echo "uiowa site because things are not binhexed. Saves work."
  63.         echo ""
  64.         echo "    grind.isca.uiowa.edu     in mac/umich (no .hqx)"
  65.         echo "    archive.umich.edu     in mac"
  66.         echo "    wuarchive.wustl.edu     in mirrors/archive.umich.edu/mac"
  67.         echo "    archive.orst.edu     in pub/mirrors/archive.umich.edu/mac"
  68.         echo "    archie.au         in micros/mac/umich"
  69.         echo "    nic.switch.ch         in mirror/umich-mac"
  70.         echo "    src.doc.ic.ac.uk    in packages/mac/umich (with .gz)"
  71.         echo "    ftp.sunet.se         in /pub/mac/mirror-umich"
  72.         echo "    ftp.inter.spin.ad.jp     in pub/Mac/Merit.mirror"
  73.         echo "    ftp.technion.ac.il     in pub/unsupported/mac/umich"
  74.         echo "    nctuccca.edu.tw     in /Macintosh/umich-mac"
  75.         echo "    anl.anl.fr         in /pub/mac/umich (with .z)"
  76.         echo ""
  77.  
  78.         echo "If you pass no arguments then the files"
  79.         echo "    /mac/00help/newthings.txt"
  80.         echo "    /mac/00ls-lRfile"
  81.         echo "will be transfered so that you may browse them for the files"
  82.         echo "you wish to download."
  83.         echo ""
  84.         echo "A file called newthings.txt.greped will be created that holds"
  85.         echo "only the complete pathnames for the newest files in the archive."
  86.         echo ""
  87.         echo "The easiest way to download files is to edit this file (newthings.txt.greped)"
  88.         echo "and delete all the lines except for the files you wish to download."
  89.         echo "Then simply rerun ftpumich with this edited file as the argument."
  90.         echo "Presto.  All the files will be obtained .. every time (practically)."
  91.         echo ""
  92.         echo "This program creates ~/.netrc macros.  Each macro can't exceed 4k"
  93.         echo "which is just less than attempting to ftp all the new files."
  94.         echo "The ~/.netrc file is used and so a backup copy is saved as"
  95.         echo "~/.netrc.ftpumich incase there is some sort of problem and"
  96.         echo "your ~/.netrc file is not restored.  Re-running this script with"
  97.         echo "will not copy of the backup but instead it will restore the"
  98.         echo "original ~/.netrc file."
  99.             echo ""
  100.             echo "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
  101.             echo ""
  102.     endif
  103.  
  104.     if ( $#argv > 1 ) then
  105.         exit 1
  106.     endif
  107. endif
  108.  
  109. if ( $#argv == 0 ) then
  110.     echo "/mac/00help/newthings.txt">    ftpumich.tmp
  111.     echo "/mac/00ls-lRfile"        >>    ftpumich.tmp
  112.     set file = ftpumich.tmp
  113.     if ( -f newthings.txt ) then
  114.         rm -f newthings.txt
  115.     endif
  116.     if ( -f 00ls-lRfile ) then
  117.         rm -f 00ls-lRfile
  118.     endif
  119. else
  120.     set file = $1
  121. endif
  122.  
  123. echo ""
  124. echo "-----------------------------------------------------------------"
  125. echo "Now attmpting to ftp the following files:"
  126. cat $file
  127. echo "-----------------------------------------------------------------"
  128. echo ""
  129.  
  130. if ( ! (-f ~/.netrc.ftpumich) && -f ~/.netrc ) then
  131.     mv ~/.netrc ~/.netrc.ftpumich
  132. endif
  133.  
  134. foreach machine ( grind.isca.uiowa.edu archive.umich.edu mirror.archive.umich.edu wuarchive.wustl.edu archive.orst.edu nic.switch.ch ftp.sunet.se ftp.inter.spin.ad.jp archie.au src.doc.ic.ac.uk anl.anl.fr ftp.technion.ac.il nctuccca.edu.tw )
  135.     @ count = 0
  136.  
  137.     echo "machine $machine" > ~/.netrc
  138.     echo "login anonymous" >> ~/.netrc
  139.     if ( -f ~/.forward ) then
  140.         echo "password `cat ~/.forward`" >> ~/.netrc
  141.     else
  142.         echo "password `echo $user`@`hostname`" >> ~/.netrc
  143.     endif
  144.     echo "macdef init" >> ~/.netrc
  145.     echo "bin" >> ~/.netrc
  146.     echo "hash" >> ~/.netrc
  147.     echo "prompt" >> ~/.netrc
  148.  
  149. # Defaults:
  150.     set hqx = .hqx
  151.     set suffix = ""
  152.  
  153.     switch ($machine)
  154.     case    grind.isca.uiowa.edu:
  155.             set dir = /mac/umich
  156.             set hqx = 
  157.             breaksw
  158.     case    archive.umich.edu:
  159.             set dir = /mac
  160.             breaksw
  161.     case    mirror.archive.umich.edu:
  162.             set dir = /pub/mirrors/archive.umich.edu/mac
  163.             breaksw
  164.     case     wuarchive.wustl.edu:
  165.             set dir = /mirrors/archive.umich.edu/mac
  166.             breaksw
  167.     case     archive.orst.edu:
  168.             set dir = pub/mirrors/archive.umich.edu/mac
  169.             breaksw
  170.     case    nic.switch.ch:
  171.             set dir = mirror/umich-mac
  172.             breaksw
  173.     case    ftp.sunet.se:
  174.             set dir = /pub/mac/mirror-umich
  175.             breaksw
  176.     case    ftp.inter.spin.ad.jp:
  177.             set dir = pub/Mac/Merit.mirror
  178.             breaksw
  179.     case    archie.au:
  180.             set dir = /micros/mac/umich
  181.             breaksw
  182.     case    ftp.technion.ac.il:
  183.             set dir = pub/unsupported/mac/umich
  184.             breaksw
  185.     case    src.doc.ic.ac.uk:
  186.             set dir = /packages/mac/umich
  187.             set suffix = ".gz"
  188.             breaksw
  189.     case    anl.anl.fr:
  190.             set dir = /pub/mac/umich
  191.             set suffix = ".z"
  192.             breaksw
  193.     case    nctuccca.edu.tw:
  194.             set dir = /Macintosh/umich-mac
  195.             breaksw
  196.     endsw
  197.     echo "### /;^) Attmepting to connect to $machine /;^) ###"
  198.  
  199.     echo ""
  200.     echo "cd $dir" >> ~/.netrc
  201.     cat $file | sed -e 's/^\/mac\///' | sed -e 's/.hqx//' | awk -F/ '{print "get", $0"'$hqx$suffix'", $NF"'$hqx$suffix'" }' >> ~/.netrc
  202.     endif
  203.     echo "quit" >> ~/.netrc
  204.     echo "" >> ~/.netrc
  205.     chmod 600 ~/.netrc
  206.     
  207.     set length_before = `/bin/ls -l | wc -l`
  208.     
  209.     while ( `/bin/ls -l | wc -l` <= $length_before && $count < $maxcount )
  210.         ( echo "quit" ) | ftp $machine
  211.         if ( `/bin/ls -l | wc -l` == $length_before ) then
  212.             @ count ++
  213.             echo ""
  214.             echo "### /:^( Attempt #"$count" of $maxcount to connect to $machine has failed. /:^( ###"
  215.             echo ""
  216.             echo "-----------------------------------------------------------------"
  217.             echo ""
  218.             sleep $sleep_time
  219.         else
  220.             echo ""
  221.             echo "-----------------------------------------------------------------"
  222.             echo ""
  223.             @ new = `/bin/ls -l | wc -l` - $length_before
  224.             echo "Finished ftp'ing (Successfully I think. Number of new files = ($new)"
  225.             echo ""
  226.             mv ~/.netrc.ftpumich ~/.netrc
  227.             chmod 600 ~/.netrc
  228.             rm -f ftpumich.tmp
  229.             if ( $#argv == 0 ) then
  230.                 if ( -f newthings.txt.gz ) then
  231.                     unzip newthings.txt.gz
  232.                 endif
  233.                 if ( -f newthings.txt.Z ) then
  234.                     uncompress newthings.txt.Z
  235.                 endif
  236.                 cat newthings.txt | grep "^\/mac\/" > newthings.txt.greped
  237.                 echo ""
  238.                 echo "Please edit the file called (newthings.txt.greped) and delete the lines"
  239.                 echo "that contain filenames you do not wish to ftp."
  240.                 compress 00ls-lRfile
  241.                 echo ""
  242.             endif
  243.             exit 0
  244.         endif
  245.     end
  246.  
  247. end
  248.  
  249. echo "All attempts to ftp have failed."
  250. mv ~/.netrc.ftpumich ~/.netrc
  251. chmod 600 ~/.netrc
  252. rm -f ftpumich.tmp
  253.